package com.example.xinli.controller;

import com.example.xinli.service.IRecordService;
import com.example.xinli.service.IUserService;
import com.example.xinli.utils.TokenUtil;
import com.example.xinli.domain.vo.ResponseBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IRecordService recordService;

    // 获取用户的所有干预记录
    @RequestMapping("/getAllUserRecord")
    @ResponseBody
    public ResponseBean getAllUserRecord(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        token = token.split(" ")[1];
        String userId = TokenUtil.getId(token);
        return recordService.getAllUserRecord(userId);
    }

    // 获取用户的某一条干预记录
    @RequestMapping("/getUserRecord")
    @ResponseBody
    public ResponseBean getUserRecord(HttpServletRequest request, @RequestParam("interId") int interId) {
        String token = request.getHeader("Authorization");
        token = token.split(" ")[1];
        String userId = TokenUtil.getId(token);
        return recordService.getUserRecord(userId, interId);
    }
}

